import configs from '../static/config.js'
const baseUrl = configs.ApiUrl  
const service = (api = '', date = {}, type = 'GET', header = {
}) => {
    return new Promise((resolve, reject) => {
		
        uni.request({
            method: api.method,
            url: baseUrl + api.url,
            data: api.data,
            header: {
					'Content-Type': 'application/x-www-form-urlencoded'
				},
            dataType: 'json',         
        }).then((response) => {
            setTimeout(function() {
                uni.hideLoading();
            }, 200);
            let [error, res] = response;
			 if(error==null){
					  if(res.data.code === 1){
						  resolve(res.data); 
					  }else{
						  uni.showToast({
							  icon:'error',
						      title: res.data.msg,
						      duration: 2000
						  });
					  }
			 }  	
						 else{
							uni.showToast({
								title: '请求超时，请重试',
								icon: 'error', //将值设置为 success 或者 ''
								duration: 2000 //持续时间为 2秒
							})  
							reject(err)
						  }
				    
				
			
          
		
        })
			
    });
}
export default service
